29. Consider that there are three processes in ready queue and 9 free memory
frame and processes has the following page reference string:
P1:11, 12, 13, 14, 12, 11
P2: 15, 16, 12, 11, 12, 13
P3: 17, 16, 13, 12, 11, 12
And use equal partitioning method and allocate initial set of frame to all the
three process. How many page faults would occur for the LRU replacement
algorithm using local replacement policy? Remember that all frames are
initially empty, so your first unique pages will all cost one fault each.
Program :
#include<stdio.h>
int findLRU(int time[], int n){
int i, minimum = time[0], pos = 0;
for(i = 1; i < n; ++i){
if(time[i] < minimum){
minimum = time[i];
pos = i;
}
}
return pos;
}
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10],
flag1, flag2, i, j, pos, faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf("%d", &no_of_pages);
printf("Enter reference string: ");
for(i = 0; i < no_of_pages; ++i){
scanf("%d", &pages[i]);
}
for(i = 0; i < no_of_frames; ++i){
frames[i] = -1;
}
for(i = 0; i < no_of_pages; ++i){
flag1 = flag2 = 0;
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == pages[i]){
counter++;
time[j] = counter;
flag1 = flag2 = 1;
break;
}